#pragma once
#ifndef ERROR_H
#define ERROR_H

#define MAX_ERR_MSG		1024


#define DP( a )\
{\
	char buff[MAX_ERR_MSG];\
	sprintf( buff, a );\
	OutputDebugStringA( buff );\
}

#define DP0 DP

#define DP1( a, b )\
{\
	char buff[MAX_ERR_MSG];\
	sprintf( buff, a, b );\
	OutputDebugStringA( buff );\
}

#define DP2( a, b, c )\
{\
	char buff[MAX_ERR_MSG];\
	sprintf( buff, a, b, c );\
	OutputDebugStringA( buff );\
}

#define DP3( a, b, c, d )\
{\
	char buff[MAX_ERR_MSG];\
	sprintf( buff, a, b, c, d );\
	OutputDebugStringA( buff );\
}

#define DP4( a, b, c, d, e )\
{\
	char buff[MAX_ERR_MSG];\
	sprintf( buff, a, b, c, d, e );\
	OutputDebugStringA( buff );\
}


class CError
{
protected:
	char		m_strMsg[MAX_ERR_MSG];
	HRESULT		m_hrError;

public:
	CError( HRESULT hr )
	{
		m_hrError = hr;
	}

	CError( const char* strFile, u32 atLine, const char* strMsg="\0" )
	{
		_snprintf( m_strMsg, MAX_ERR_MSG, "Error in file %s at line %d: %s", strFile, atLine, strMsg );
		m_hrError = E_FAIL;
	}
	const char* GetErrorMsg()	{ return m_strMsg; }
	HRESULT		GetErrorCode()	{ return m_hrError; }
};

class CMemoryError : public CError
{
public:
	CMemoryError( u32 numBytes, const char* strFile, u32 atLine ) : CError( E_OUTOFMEMORY )
	{
		_snprintf(	m_strMsg, MAX_ERR_MSG, "Error allocating memory of %d bytes in file %s at line %d", 
					numBytes, strFile, atLine );
	}
};


#endif // ERROR_H